package exp.baseline;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintStream;
import java.io.UnsupportedEncodingException;

import tools.FileReaderEnhance;
import tools.twitter.TweetTidy;
import dragon.ir.index.sentence.OnlineSentenceIndexer;
import dragon.ir.summarize.LexRankSummarizer;
import dragon.nlp.extract.BasicConceptFilter;
import dragon.nlp.extract.BasicTokenExtractor;
import dragon.nlp.tool.lemmatiser.EngLemmatiser;
import dragon.onlinedb.ArrayCollectionReader;
import dragon.onlinedb.BasicArticle;
import dragon.onlinedb.trec.SgmArticleParser;

public class Lexrank {
	public static final String filepath = "data/_newData/plainText_filtered/";
	
	public static void main(String[] args) {
		System.err.println("Processing: " + args[0]);
		EngLemmatiser el = new EngLemmatiser("data/_DragonTool/nlpdata/lemmatiser", false, true);
		
		BasicTokenExtractor bte = new BasicTokenExtractor(el);
		bte.setSubConceptOption(false);
		bte.setFilteringOption(true);
		BasicConceptFilter cf = new BasicConceptFilter("data/_DragonTool/nlpdata/exp/rijsbergen.stopword");
		bte.setConceptFilter(cf);
		
		OnlineSentenceIndexer osi = new OnlineSentenceIndexer(bte, false);
		osi.setMinSentenceLength(9);
		//only body
		osi.screenArticleContent(false, false, true);
		
		LexRankSummarizer lrs = new LexRankSummarizer(osi, true);
		lrs.setSimilarityThreshold(0.1);
		lrs.setContinuousScoreOpiton(true);
		
		ArrayCollectionReader cr = new ArrayCollectionReader();
		cr.setArticleParser(new SgmArticleParser());
		String [] tweets = FileReaderEnhance.readToString(filepath + args[0], "UTF-8").split("\n");
		for (String t : tweets) {
			t = TweetTidy.doTidyAll(t);
//			System.out.println(t);
			BasicArticle a = new BasicArticle();
			a.setKey(String.valueOf(t.hashCode()));
			a.setBody(t);
//			a.setTitle(t);
//			a.setAbstract(t);
			cr.addArticle(a);
		}
		
		try {
			System.setOut(new PrintStream(new File("./" + args[0] + ".out"), "UTF-8"));
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		
		System.out.println(lrs.summarize(cr, Integer.parseInt(args[1])));		
	}
}
